package com.gcl.rabbitmq;

import com.gcl.rabbitmq.utils.RabbtMQUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Consumer01 {


    public static void main(String[] args) throws IOException, TimeoutException {

        Channel channel = RabbtMQUtils.getChannel();

        // 声明直接路由器
        channel.exchangeDeclare(Producer.EXCHANGE_NAME, BuiltinExchangeType.DIRECT);

        // 创建临时队列
        channel.queueDeclare("cons", false, false, false, null);

        // 队列绑定交换机
        channel.queueBind("cons", Producer.EXCHANGE_NAME, "info");
        channel.queueBind("cons", Producer.EXCHANGE_NAME, "waring");


        // 消费消息

        DeliverCallback deliverCallback = (consumeTag, deliver) -> {
            System.out.println("打印 " + new String(deliver.getBody()));
        };
        CancelCallback cancelCallback = (consumeTag) -> {};
        channel.basicConsume("cons", true, deliverCallback, cancelCallback);

    }


}
